/*
 * Exploder
 * 
 * Tero Pyylampi (218437), Jussi Tuurinkoski (211594)
 *
 * Wooden border for the game to protect and serve
 */

#include "GameBorderWood.h"
#include "../../../../Resources.h"

using namespace cocos2d;

// default constructor
GameBorderWood::GameBorderWood( b2World *world, cocos2d::CCLayer *layer, GameCamera *camera, b2Vec2 worldPos )
	: GameBorder( world, layer, camera, 1500 ) {

	// init physic object
	ObjectProperties properties( 1.0f, 2.0f, 0.5f );
	b2Body *b = createBox( true, 1.0f, 4.0f, worldPos.x, worldPos.y, properties );
	mBodies->push_back( b );

	// init normal sprite
	mBorderSprite = CCSprite::spriteWithFile( getResource( Textures::GAME_BORDER_WOOD ) );
	mBorderSprite->setScale( RATEX * 0.322f );
	layer->addChild( mBorderSprite, Z_LAYER_GAME_MIDDLE );

	// broken sprite init
	mBrokenSprite = CCSprite::spriteWithFile( getResource( Textures::GAME_BORDER_WOOD_BROKEN ) );
	mBrokenSprite->setScale( RATEX * 0.322f );
	mBrokenSprite->retain();

	// update once
	update( 0 );
}

// default destructor
GameBorderWood::~GameBorderWood() {

}

// default update function
void GameBorderWood::update( cocos2d::ccTime dt ) {
	GameBorder::update( dt );
}

// object takes damage as a result of a collision
void GameBorderWood::takeDamage( float damage, b2Body *bodyTakingDamage ) {
	GameBorder::takeDamage( damage, bodyTakingDamage );
	// TODO: damage explosion, splinters etc. ?
}

// break and remove object
void GameBorderWood::breakObject() {
	GameBorder::breakObject();
}

// change to broken sprite
void GameBorderWood::changeToBrokenSprite() {
	GameBorder::changeToBrokenSprite();
}

// get the main type of the object
PhysicObjectItems GameBorderWood::getObjectType() {
	return BORDER_WOOD;
}

